# [expression for循环]
ls = [x*2 for x in range(8)]
print('ls--------->',ls)

# [expression for循环 if条件判断]
ls1 = [x*3 for x in range(15) if x%2 == 0]
print(ls1)

# [expression1 if条件判断 else expression2 for循环]
ls2 = [x*3 if x%2 == 0 else x for x in range(15)]
print('ls2------->',ls2)

# [expression for循环嵌套 if条件判断]
ls3 = [(x,y) for x in range(3) for y in range(4)]
print('ls3---->',ls3)

ls4 = [(x,y) for x in range(3) for y in range(4) if y>2]
print('ls4------->',ls4)

ls5 = [(x,y) if y>2 else (x*2,y*2) for x in range(3) for y in range(4)]
print('ls5-------->',ls5)

# 列表生成式和函数之间搭配,找到1-100之间质数
def find_zhshu(num):
    if num == 1:
        return False
    for i in range(2,num):
        res = num % i
        if res == 0:
            return False
        else:
            return True
print([j for j in range(1,101) if find_zhshu(j)])